package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.common.enums.AppHttpCodeEnum;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理API")
public class WmChannelController {

    @Autowired
    private IWmChannelService channelService;

    /**
     * 根据频道名称分页查询列表
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "根据频道名称分页查询列表", notes = "author:mcm")
    @ApiImplicitParam(name = "dto", value = "查询对象", required = true, dataType = "ChannelDto")
    @PostMapping("/list")
    public ResponseResult listByName(@RequestBody ChannelDto dto) {
        // try {
        return channelService.listByName(dto);
        // } catch (Exception e) {
        //     return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
        // }
    }

    /**
     * 新增频道
     *
     * @param entity
     * @return
     */
    @ApiOperation(value = "新增频道", notes = "author:mcm")
    @ApiImplicitParam(name = "entity", value = "频道对象", required = true, dataType = "WmChannel")
    @PostMapping
    public ResponseResult saveWmChannel(@RequestBody WmChannel entity) {
        return channelService.saveWmChannel(entity);
    }

    /**
     * 查询所有频道
     *
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult channels() {
        List<WmChannel> list = channelService.list();
        return ResponseResult.okResult(list);
    }
}
